<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="timesheet.aspx.cs" Inherits="Stratman.Web.VSTS.Timesheet" %>

<%@ Register Src="UserControls/initializer.ascx" TagName="initializer" TagPrefix="uc5" %>
<%@ Register Src="UserControls/htmlheader.ascx" TagName="htmlheader" TagPrefix="uc3" %>
<%@ Register Src="UserControls/header.ascx" TagName="header" TagPrefix="uc1" %>
<%@ Register Src="UserControls/footer.ascx" TagName="footer" TagPrefix="uc2" %>

<html>

<uc3:htmlheader ID="hh1" runat="server" />

<body>
    <script language="javascript" type="text/javascript">
        var changeQueue = new Array();
        
        function PerformSave()
        {
            changedEntries = document.all("changedEntries");
        
            for (key in changeQueue)
            {            
                if (changeQueue[key] != null)
                    changedEntries.value += key + "," + changeQueue[key] + ",";
            }
            
            if (changedEntries.value != "")
                changedEntries.value = changedEntries.value.substring(0, changedEntries.value.length - 1);
                
            document.all("form2").submit();
        }
    
        function AddChangeToQueue(workItemId, dayIndex, textBox, originalValue)
        {
            var decimalRegex = /^\d(\.\d+){0,1}$/;
            var timeRegex = /^\d{1,2}:[0-5]\d{1}$/;
            
            if (!timeRegex.test(textBox.value) && textBox.value != "")
            {
                if (decimalRegex.test(textBox.value))
                {
                    var hours = Math.floor(textBox.value);
                    var minutes = Math.round((textBox.value - Math.floor(textBox.value)) * 60);
                    
                    if (minutes < 10)
                        minutes = "0" + minutes;
                    
                    textBox.value = hours + ":" + minutes;
                }
            
                else
                {
                    textBox.focus();
                    alert("Please enter your time in HH:MM format.");
                    return;
                }
            }
        
            if (textBox.value == originalValue)
            {
                textBox.style.backgroundColor = "";
                changeQueue[workItemId + "_" + dayIndex] = null;
                return;
            }
            
            changeQueue[workItemId + "_" + dayIndex] = textBox.value;
            textBox.style.backgroundColor = "#dbacac";
        }
    </script>
    
    <form id="form1" runat="server">
        <uc5:initializer ID="is1" runat="server" />
        <uc1:header ID="ph1" runat="server" />
        
        <asp:Literal ID="titleLiteral" runat="server" />
    
        <asp:Panel ID="problemsPanel" runat="server" CssClass="ErrorMessage" Visible="false">
            <asp:Literal ID="problemsLiteral" runat="server" />
        </asp:Panel>
    
        <asp:Panel ID="contentPanel" runat="server">
            <div style="width: 100%; vertical-align: middle">
                <center>
            	    <table cellpadding="6" cellspacing="0" border="0">
            		    <tr>
                		    <td valign="bottom">
                			    <asp:HyperLink runat="server" ID="previousWeek"><img src="Images/moveprevious.gif" border="0" valign="bottom" /></asp:HyperLink>
                		    </td>
                		    <td valign="top">
                			    <h3><font color="#555555">Week beginning <asp:Label ID="startOfWeekLabel" runat="server" /></font></h3>
                		    </td>
                		    <td valign="bottom">
                			    <asp:HyperLink runat="server" ID="nextWeek"><img src="Images/movenext.gif" border="0" valign="bottom" /></asp:HyperLink>
                		    </td>
                	    </tr>
                    </table>
                </center>
            </div>
            
            <asp:DataGrid ID="timesheetDataGrid" runat="server" AutoGenerateColumns="False" Width="100%" HeaderStyle-HorizontalAlign="Center" ShowFooter="true" OnItemDataBound="dataGridItem_DataBound" CellPadding="3" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center" BorderStyle="Solid" BorderWidth="1" BorderColor="#DDDDDD" EnableViewState="false">
                <Columns>
                    <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" FooterStyle-HorizontalAlign="Left">
                        <HeaderTemplate>
                            Work Item
                        </HeaderTemplate>
                        <ItemTemplate>
                            <%# Eval("workItemType") %>: <a href='workitem.aspx?id=<%# Eval("workItemId") %>'><%# Eval("workItemTitle") %></a>
                        </ItemTemplate>
                        <FooterTemplate>
                            Total
                        </FooterTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn>
                        <ItemTemplate>
                            <asp:TextBox EnableViewState="false" ID="sundayTime" runat="server" Columns="4" Text='<%# ConvertToTimeString(Convert.ToDecimal(Eval("sundayTime"))) %>' OnDataBinding="timesheetEntry_DataBinding" />
                            <asp:Literal ID="sundayTimeReadOnly" runat="server" Text='<%# ConvertToTimeString(Convert.ToDecimal(Eval("sundayTime"))) %>' OnDataBinding="timesheetEntry_DataBinding" />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn>
                        <ItemTemplate>
                            <asp:TextBox EnableViewState="false" ID="mondayTime" runat="server" Columns="4" Text='<%# ConvertToTimeString(Convert.ToDecimal(Eval("mondayTime"))) %>' OnDataBinding="timesheetEntry_DataBinding" />
                            <asp:Literal ID="mondayTimeReadOnly" runat="server" Text='<%# ConvertToTimeString(Convert.ToDecimal(Eval("mondayTime"))) %>' OnDataBinding="timesheetEntry_DataBinding" />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn>
                        <ItemTemplate>
                            <asp:TextBox EnableViewState="false" ID="tuesdayTime" runat="server" Columns="4" Text='<%# ConvertToTimeString(Convert.ToDecimal(Eval("tuesdayTime"))) %>' OnDataBinding="timesheetEntry_DataBinding" />
                            <asp:Literal ID="tuesdayTimeReadOnly" runat="server" Text='<%# ConvertToTimeString(Convert.ToDecimal(Eval("tuesdayTime"))) %>' OnDataBinding="timesheetEntry_DataBinding" />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn>
                        <ItemTemplate>
                            <asp:TextBox EnableViewState="false" ID="wednesdayTime" runat="server" Columns="4" Text='<%# ConvertToTimeString(Convert.ToDecimal(Eval("wednesdayTime"))) %>' OnDataBinding="timesheetEntry_DataBinding" />
                            <asp:Literal ID="wednesdayTimeReadOnly" runat="server" Text='<%# ConvertToTimeString(Convert.ToDecimal(Eval("wednesdayTime"))) %>' OnDataBinding="timesheetEntry_DataBinding" />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn>
                        <ItemTemplate>
                            <asp:TextBox EnableViewState="false" ID="thursdayTime" runat="server" Columns="4" Text='<%# ConvertToTimeString(Convert.ToDecimal(Eval("thursdayTime"))) %>' OnDataBinding="timesheetEntry_DataBinding" />
                            <asp:Literal ID="thursdayTimeReadOnly" runat="server" Text='<%# ConvertToTimeString(Convert.ToDecimal(Eval("thursdayTime"))) %>' OnDataBinding="timesheetEntry_DataBinding" />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn>
                        <ItemTemplate>
                            <asp:TextBox EnableViewState="false" ID="fridayTime" runat="server" Columns="4" Text='<%# ConvertToTimeString(Convert.ToDecimal(Eval("fridayTime"))) %>' OnDataBinding="timesheetEntry_DataBinding" />
                            <asp:Literal ID="fridayTimeReadOnly" runat="server" Text='<%# ConvertToTimeString(Convert.ToDecimal(Eval("fridayTime"))) %>' OnDataBinding="timesheetEntry_DataBinding" />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn>
                        <ItemTemplate>
                            <asp:TextBox EnableViewState="false" ID="saturdayTime" runat="server" Columns="4" Text='<%# ConvertToTimeString(Convert.ToDecimal(Eval("saturdayTime"))) %>' OnDataBinding="timesheetEntry_DataBinding" />
                            <asp:Literal ID="saturdayTimeReadOnly" runat="server" Text='<%# ConvertToTimeString(Convert.ToDecimal(Eval("saturdayTime"))) %>' OnDataBinding="timesheetEntry_DataBinding" />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn>
                        <ItemTemplate>
                            <%# ConvertToTimeString(Convert.ToDecimal(Eval("total")), true) %>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                </Columns>
            </asp:DataGrid>
            
            <table cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td align="right">Completed:</td>
                    <td>
                        <asp:RadioButtonList ID="completedRadioButtonList" runat="server" RepeatDirection="Horizontal">
                            <asp:ListItem Text="Yes" Value="Yes" />
                            <asp:ListItem Text="No" Value="No" Selected="true" />
                        </asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td align="right" valign="top" style="padding-top: 5px">Approved:</td>
                    <td valign="top">
                        <asp:RadioButtonList ID="approvedRadioButtonList" runat="server" RepeatDirection="Horizontal">
                            <asp:ListItem Text="Yes" Value="Yes" />
                            <asp:ListItem Text="No" Value="No" />
                        </asp:RadioButtonList>
                        <asp:Panel ID="commentsPanel" runat="server" Visible="false">
                            Comments<asp:Literal ID="commentsSourceLiteral" runat="server" Visible="false" />:<br />
                            <asp:TextBox ID="commentsTextBox" runat="server" Visible="false" Rows="4" Columns="60" TextMode="MultiLine" />
                            <asp:Literal ID="commentsLiteral" runat="server" Visible="false">(None)</asp:Literal>
                        </asp:Panel>
                    </td>
                </tr>
            </table>
        </asp:Panel>
        
        <uc2:footer ID="fo1" runat="server" />
    </form>
    
    <form id="form2" action="timesheet.aspx<%=(Request.QueryString.Count != 0 ? "?" + Request.QueryString : "") %>" method="post">
        <input type="hidden" id="changedEntries" name="changedEntries" />
        <input type="hidden" id="completedState" name="completedState" />
        <input type="hidden" id="approvedState" name="approvedState" />
        <input type="hidden" id="comments" name="comments" />
    </form>
</body>
</html>
